package com.hancher.plugins.hrasm9log;

import com.android.build.api.extension.impl.VariantSelectorImpl;
import com.android.build.api.instrumentation.FramesComputationMode;
import com.android.build.api.instrumentation.InstrumentationScope;
import com.android.build.api.variant.AndroidComponentsExtension;
import com.android.build.api.variant.impl.VariantImpl;

import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

public class HrAsmLogPluginProject implements Plugin<Project> {
    // region 插件生命周期
    @Override
    public void apply(Project target) {
        System.out.println("========HrAsmLogPluginProject==========apply");

        AndroidComponentsExtension androidComponents = target.getExtensions().getByType(AndroidComponentsExtension.class);
        androidComponents.onVariants(new VariantSelectorImpl(), (Action<VariantImpl>) variant -> {
            variant.getInstrumentation().transformClassesWith(HrAsmLogVisitorFactory.class, InstrumentationScope.PROJECT, none -> null);
            variant.getInstrumentation().setAsmFramesComputationMode(FramesComputationMode.COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS);
        });
    }
    //endregion
}